package com.xyazm.order.controller;

import com.xyazm.common.enums.OrderStatusChangeEnum;
import com.xyazm.fulfill.domain.event.OrderDeliveredEvent;
import com.xyazm.fulfill.domain.event.OrderOutStockEvent;
import com.xyazm.fulfill.domain.event.OrderSignedEvent;
import com.xyazm.order.service.IOrderTriggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单事件触发模拟
 * @Author: xuyou
 * @Date: 2022/7/21 17:28
 */
@RestController
@RequestMapping("/order/trigger")
public class OrderTriggerController {

    @Autowired
    private IOrderTriggerService orderTriggerService;

    /**
     * 触发订单发货出库事件
     * @author xuyou
     * @date: 2022/7/21 17:36
     * @param: event
     */
    @PostMapping("/triggerOutStockEvent")
    public void triggerOrderOutStockWmsEvent(@RequestBody OrderOutStockEvent event) {
        orderTriggerService.triggerOrderOutStockWmsEvent(OrderStatusChangeEnum.ORDER_OUT_STOCKED,event);
    }

    /**
     * 触发订单配送事件
     * @author xuyou
     * @date: 2022/7/21 17:36
     * @param: event
     */
    @PostMapping("/triggerDeliveredWmsEvent")
    public void triggerOrderDeliveredWmsEvent(@RequestBody OrderDeliveredEvent event) {
        orderTriggerService.triggerOrderDeliveredWmsEvent(OrderStatusChangeEnum.ORDER_DELIVERED,event);
    }

    /**
     * 触发订单签收事件
     * @author xuyou
     * @date: 2022/7/21 17:37
     * @param: event
     */
    @PostMapping("/triggerSignedWmsEvent")
    public void triggerOrderSignedWmsEvent(@RequestBody OrderSignedEvent event) {
        orderTriggerService.triggerOrderSignedWmsEvent(OrderStatusChangeEnum.ORDER_SIGNED,event);
    }


    /**
     * 触发订单已支付事件
     * @author xuyou
     * 2022/8/15 0015 21:57
     * @param orderId
    */
    @GetMapping("/triggerPaidEvent")
    public void triggerOrderPaidEvent(@RequestParam("orderId") String orderId) {
        orderTriggerService.triggerOrderPaidEvent(orderId);
    }


    /**
     * 触发接收订单履约
     * @author xuyou
     * 2022/8/15 0015 21:58
    */
    @GetMapping("/triggerReceiveOrderFulFill")
    public void triggerReceiveOrderFulFill(@RequestParam("orderId") String orderId,
                                                          @RequestParam("fulfillException") String fulfillException,
                                                          @RequestParam("wmsException") String wmsException,
                                                          @RequestParam("tmsException") String tmsException) {
        orderTriggerService.triggerReceiveOrderFulFill(orderId,fulfillException,wmsException,tmsException);
    }

}
